package chapter1;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.Test;

public class LocateRowsAndCells {
  @Test
  public void testTable() {
	  WebDriver driver = new FirefoxDriver();
	  driver.get("http://dl.dropbox.com/u/55228056/Locators.html");
	  WebElement simpleTable = driver.findElement(By.id("items"));
	  //Get all rows
	  List<WebElement> rows =
	  simpleTable.findElements(By.tagName("tr"));
	  Assert.assertEquals(3, rows.size());
	//Print data from each row
	  for (WebElement row : rows) {
	  List<WebElement> cols =
	  row.findElements(By.tagName("td"));
	  for (WebElement col : cols) {
	  System.out.print(col.getText() + "\t");
	  }
	  System.out.println();
	  }
	  driver.close();
	  }
  	
}
